<?php
/**
 * 微信打赏
 * @return 支付二维码url（String） 
 * @author yuanjiang 932625974#qq.com
 * @date 02.26.2017
*/
define('IN_T',true);
require_once '../../source/include/init.php';

//查询订单是否存在
$oid = intval($_POST['oid']);	//订单id
$res['status'] = 0; 

//查询订单是否存在
$pay_order  = $Db->query("select * from ".$Base->table('company_order')." where id=$oid",'Row');
if(!$pay_order){
	$res['msg'] = '订单不存在！';
	echo $Json->encode($res);
	exit;
}

//查询订单商家是否配置微信支付
$payment = $Db->query("select * from ".$Base->table('company_payment')." where c_id=".$pay_order['c_id']." limit 1",'Row');
if(!empty($payment)){
	unset($payment['id']);
	unset($payment['c_id']);
	$_lang['wxpay_config'] = $payment;
}

//微信支付类库
require_once ROOT_PATH."source/payment/wxpay/lib/WxPay.Api.php";
require_once ROOT_PATH."source/payment/wxpay/action/WxPay.JsApiPay.php";
require_once ROOT_PATH."source/payment/wxpay/action/log.php";

//公众号支付
//①、获取用户openid
$tools = new JsApiPay();
$openId = $_SESSION['customer']['openid'];//$tools->GetOpenid();

//②、统一下单
$input = new WxPayUnifiedOrder();
$input->SetBody("支付订单");
$input->SetAttach($pay_order['order_num']);
$input->SetOut_trade_no(WxPayConfig::$MCHID.date("YmdHis"));
$input->SetTotal_fee($pay_order['price']*100);
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag("订单编号：".$pay_order['order_num']);
$input->SetNotify_url($_lang['host']."module/payment/wxpay_notify.php");
$input->SetTrade_type("JSAPI");
$input->SetOpenid($openId);
$order = WxPayApi::unifiedOrder($input);
//print_r($order);
$jsApiParameters = $tools->GetJsApiParameters($order);
$res = array(
	'status'=>1,
	'jsApiParameters'=>$jsApiParameters,
);
//print_r($res);

echo $Json->encode($res);
exit;
?>